package com.zkca.xf.ui.activity.me;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.zkca.xf.ConstantsXF;
import com.zkca.xf.R;
import com.zkca.xf.base.BaseTitleActivity;
import com.zkca.xf.utils.LogUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HelpActivity extends BaseTitleActivity {
    @BindView(R.id.wv_info)
    WebView wv_info;
    @BindView(R.id.progressBar1)
    ProgressBar pg1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        ButterKnife.bind(this);
        setTitleText("使用帮助");
        setleftTextVisibility(true);
        setleftImgVisibility(true);
        initView();
        initdata();
    }

    private void initView(){
        wv_info.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        wv_info.getSettings().setLoadWithOverviewMode(true);
        wv_info.getSettings().setJavaScriptEnabled(true);
        wv_info.getSettings().setUseWideViewPort(true);
        wv_info.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        wv_info.getSettings().setLoadWithOverviewMode(true);
        //如果不设置WebViewClient，请求会跳转系统浏览器
        wv_info.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });

        //设置经度条
        wv_info.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO 自动生成的方法存根

                if (newProgress == 100) {
                    pg1.setVisibility(View.GONE);//加载完网页进度条消失
                } else {
                    pg1.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                    pg1.setProgress(newProgress);//设置进度值
                }

            }
        });
    }

    private void initdata() {
        wv_info.loadUrl("http://47.92.90.52:80/help.html");
    }
}
